# from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
# from transformers import pipeline
# import json
 
# model_path = './model/zh_en/'  
# #创建tokenizer
# tokenizer = AutoTokenizer.from_pretrained(model_path) 
# #创建模型 
# model = AutoModelForSeq2SeqLM.from_pretrained(model_path) 
# #创建pipeline
# pipeline = pipeline("translation", model=model, tokenizer=tokenizer)

# def zh2En(srtfile):
#     try:
#         with open(srtfile, 'r') as f:
#             jsub = json.load(f)
#         # 格式：[{'start': 1.7, 'end': 3.32, 'text': '早安北京,关注您身边的点点滴滴'}] 
#         nsrt = []
#         for sub in jsub:
#             ctext = sub["text"]
#             etext = translate(ctext)
#             sub["en"] = etext.replace('"', '\\"').replace("'", "\'")
#             nsrt.append(sub)
#         # 写入到原来的位置，替换以前的文件内容
#         if len(nsrt):
#             with open(srtfile, "w+",encoding='utf-8') as f:
#                 json.dump(nsrt, f, ensure_ascii=False, indent=4)
#         return True
#     except Exception as e:
#         return False
# def translate(chstr):
# # chinese="""
# # 中国男子篮球职业联赛（Chinese Basketball Association），简称中职篮（CBA），是由中国篮球协会所主办的跨年度主客场制篮球联赛，中国最高等级的篮球联赛，其中诞生了如姚明、王治郅、易建联、朱芳雨等球星。"""
#     result = pipeline(chstr)
#     return(result[0]['translation_text'])